﻿using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.ClientCommand;
using MediatR;
using SqlSugar;

namespace B.S.Procurement.Read.Api.Application.CommandHander.ClientCommandHander
{
    public class ShowClientCommandHander : IRequestHandler<ShowClientCommand, ApiResult<List<Client>>>
    {
        private readonly IMediator mediator;
        private readonly ISqlSugarClient db;

        public ShowClientCommandHander(IMediator mediator, ISqlSugarClient db)
        {
            this.mediator = mediator;
            this.db = db;
        }

        public async Task<ApiResult<List<Client>>> Handle(ShowClientCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Client>> result = new ApiResult<List<Client>>();

            var list = await db.Queryable<Client>()
                                .Where(x => x.Del == false && x.ClientId == request.ClientId)
                                .ToListAsync();

            result.Data = list;

            result.Code = ApiEnum.success;
            result.Msg = "查询成功";

            return await Task.FromResult(result);
        }
    }
}
